import Taro, { Component } from '@tarojs/taro'
import { View, Text, Swiper, SwiperItem, Image } from '@tarojs/components'
import './firstEntry.css'
import { AtCurtain,AtButton } from 'taro-ui'
import app from '../../main';
import ed001 from '../../img/ed001.png'
import ed002 from '../../img/ed002.png'
import ed003 from '../../img/ed003.png'
import touxiang from '../../img/touxiang3.png'
import shouye from '../../img/shouye2.png'
// import photo from '../../img/item_image.png'
import right from '../../img/right.png'

export default class FirstEntry extends Component {

  config = {
    navigationBarTitleText: '首页'
  }

  constructor(){
    super(...arguments);
    this.state={
        //轮播图数据
        lunboList: [],
        //科普内容
        kepulist: [],
        kuputotal: 0,
    }
  }

   //获取科普内容数据
    getData() {
        let me = this;
        let data = { offset: 0, length: 4 };
        let code = { code: 101 }
        //获取轮播图数据
        app.get('web/advertisement/banners', code, function (res) {
            me.setState({
                lunboList: res.data.result
            })
        })
        //获取科普数据
        app.post('video_recommends/homeVideo', data, function (res) {
            me.setState({
                kepulist: res.data.result.data,
                kuputotal: res.data.result.total
            })
        })
        
    }

    authorize(){
        Taro.showModal({
                title:'登陆提示',
                content:'登陆之后可查看详细内容，是否微信授权登陆',
            }).then(res=>{
                if(res.confirm){
                    if(app.isEmpty(app.current.head_image)){
                        app.navigateTo('/pages/authlogin/authlogin')
                    }else if(app.isEmpty(app.current.phone)){
                        app.navigateTo('/pages/authphone/authphone')
                    }
                }else{
                    
                }
        })
    }


  componentWillMount () {
    console.log('c_params', this.$router.params);
    this.getData()
    console.log(app.current)
    
  }

  componentDidMount () {}

  componentWillUnmount () { }

  componentDidShow () { }

  componentDidHide () { }
   
  render () {
    return (
        <View className='eye-doctor'>
            {/* <View style={this.state.home}> */}
            <View className='top-body'>
                <View className='top-body-title' onClick={this.authorize.bind(this)}>
                    <View>
                        <Text className='title'>我的医生</Text>
                    </View>
                    <View className='head-image'>
                        <Image className='body-title-image' src={right} />
                    </View>
                </View>
            </View>
            <View className='body-grid'>
                <View className='grid-col' onClick={this.authorize.bind(this)}>
                    <Image className='grid-image' src={ed001} />
                    <Text className='title'>快速咨询</Text>
                </View>
                <View className='grid-col' onClick={this.authorize.bind(this)}>
                    <Image className='grid-image' src={ed002} />
                    <Text className='title'>找医生</Text>
                </View>
                <View className='grid-col' onClick={this.authorize.bind(this)}>
                    <Image className='grid-image' src={ed003} />
                    <Text className='title'>找医院</Text>
                </View>
            </View>
            <View className='body-swiper'>
                <Swiper
                indicatorColor='rgba(0, 0, 0, .3)'
                indicatorActiveColor='#ffffff'
                circular
                indicatorDots
                interval={3000}
                autoplay>
                {this.state.lunboList.map((item) => {
                    return <SwiperItem>
                    <View><Image className='swiper-image' src={app.getPath(item.image)} onClick={this.authorize.bind(this)}/></View>
                    </SwiperItem>
                })}
                </Swiper>
            </View>
            <View className='button'>
                <View className='botton-title' onClick={this.authorize.bind(this)}>
                    <View>
                        <Text className='title'>爱眼科普</Text>
                    </View>
                    <View >
                        <Text className='title'>更多></Text>
                    </View>
                </View>
                <View className='buttom-imageinfo'>
                {this.state.kepulist.map((item) => {
                    return <View className='buttom-imageinfo-box' onClick={this.authorize.bind(this)}>
                        <View className='buttom-imageinfo-image'>
                            <View><Image mode='widthFix' className='buttom-image' src={item.image} /></View>
                            <View className='titleH'><View className='title2'>{item.title}</View></View>
                        </View>
                        <View className='buttom-imageinfo-text'>
                            <View className='buttom-imageinfo-text-useravider'>
                            <Image className='text-useravider' src={item.head_image} />
                            </View>
                            <View className='buttom-imageinfo-text--userdir'>
                            <View className='buttom-imageinfo-text-a'><Text>{item.doctor_name}</Text><Text style='margin-left:5px;'>{item.positional_title}</Text></View>
                            <View className='buttom-imageinfo-text-b'><Text>{item.hospital}</Text></View>
                            </View>
                        </View>
                    </View>
                })}
                </View>
            </View>
            <View className='empty'></View>
            <View className='bottonBtn' >
                <View className="bottonBtntext" >
                    <View><Image className="btnImage" src={shouye} /></View>
                    <View><Text className='t'>首页</Text></View>
                </View>
                <View className='bottonBtntext' onClick={this.authorize.bind(this)}>
                    <View><Image className="btnImage" src={touxiang} /></View>
                    <View>我的</View>
                </View>
            </View>
      </View>
    )
  }
}
